<template>
    <van-nav-bar title="我的地址" left-text="返回" left-arrow @click-left="onClickLeft" />
    <van-address-edit :area-list="areaList" show-delete show-set-default show-search-result :search-result="searchResult"
        :area-columns-placeholder="['请选择', '请选择', '请选择']" @save="onSave" @delete="onDelete"
        @change-detail="onChangeDetail" />
</template>
<script lang="ts" setup>
import { ref, onUpdated } from 'vue';
import { showToast } from 'vant';
import { areaList } from '@vant/area-data';
import { onMounted } from 'vue';
import store from '@/store';
import { getAddress } from '../../request'



const searchResult: any = ref([]);

const onSave = (value: any) => {
    showToast('save')
    console.log(value);
    let { name, tel, addressDetail, city, conty, isDefault, province } = value
    console.log(name);
    store.state.name = name;
    store.state.tel = tel
    store.state.addressDetail = addressDetail
    store.state.city = city
    store.state.conty = conty
    store.state.isDefault = isDefault
    store.state.province = province
    console.log(store.state);

    getAddress({ address_name: addressDetail }).then((content: any) => {
        console.log(content);

    }).catch(error => {
        console.log(error);

    })

};
const onDelete = (value: any) => {
    showToast('delete')
    console.log(value);

};
const onChangeDetail = (val: any) => {
    if (val) {
        searchResult.value = [
            {
                name: '城鳌大道东路999号粤嵌科技',
                // address: '杭州市西湖区',
            }
        ];
    } else {
        searchResult.value = [];
    }
};

onMounted(() => {
    const aa: any = document.querySelector(".van-field__control");
    console.log(aa.innerHTML);

})

const onClickLeft = () => history.back();


</script>